package com.zjj.algorithm.learning.dmsxl.doublepoint;

/**
 * @author zjj_admin
 * @date 2022/12/22 14:53
 */
public class DoublePoint_01_RemoveItem {

    public static void main(String[] args) {
        int[] nums = new int[]{3, 2, 4, 5, 3, 5, 2};
        int num = removeElement(nums, 3);
        System.out.println("num = " + num);
    }

    /**
     * 使用双指针方法解题
     * @param nums
     * @param val
     * @return
     */
    public static int removeElement(int[] nums, int val) {
        if(nums.length == 0){
            return 0;
        }
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] != val){
                count ++;
            }
        }
        return count;
    }
}
